<extend name="Base:main" />
<block name="script">
	<link rel="stylesheet" href="__PUBLIC__/seller/js/uploadify/uploadify.css" />
	<script src="__PUBLIC__/seller/js/uploadify/jquery.uploadify.min.js"></script>
	<link href="__PUBLIC__/seller/js/editor/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="__PUBLIC__/seller/js/editor/third-party/template.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/seller/js/editor/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="__PUBLIC__/seller/js/editor/umeditor.min.js"></script>
    <script type="text/javascript" src="__PUBLIC__/seller/js/editor/lang/zh-cn/zh-cn.js"></script>
    <script src="__PUBLIC__/seller/js/calendar/WdatePicker.js"></script>
</block>
<block name="content">
    <div class="tpl-content-wrapper">
            <div class="tpl-content-page-title">
                商品管理
            </div>
            <ol class="am-breadcrumb">
                <li><a href="#" class="am-icon-home">首页</a></li>
                <li><a href="#">商品管理</a></li>
                <li class="am-active">添加商品</li>
            </ol>
            <div class="tpl-portlet-components">
                <div class="portlet-title">
                      <div class="caption font-green bold">
                        <span class="am-icon-code"></span>添加
                    </div>
                </div>
            <div class="tpl-block ">
                        <div class="am-g tpl-amazeui-form">
                                <div class="am-u-sm-12 am-u-md-11">
                                        <form class="am-form am-form-horizontal" request_type="parent" action="" name="myfromSubmit" method="post">
                                            <input name="goods" type="hidden" id="goods" value="{$info.goods}">
                                                <div class="am-form-group">
                                                        <label for="user-name" class="am-u-sm-3 am-form-label">模板名称</label>
                                                        <div class="am-u-sm-9">
                                                                <span><input type="text" datatype="*"  name="name" value="{$info.name}" placeholder="模板名称"></span>
                                                                <span><small>例如：xxx</small></span>
                                                        </div>
                                                </div>
                                            <div class="am-form-group">
                                                        <label for="user-email" class="am-u-sm-3 am-form-label">类别</label>
                                                        <div class="am-u-sm-9">
                                                                              <label class="am-radio-inline">
                                                                                <input type="radio"  name="type" value="1"  required=""  checked="checked"  class="am-field-valid"> 按件
                                                                              </label>

                                                        </div>    

                                            </div>
                                                <div class="am-form-group">
                                                        <label for="user-name" class="am-u-sm-3 am-form-label">商品关键字</label>
                                                        <div class="am-u-sm-9">
                                                            <div class="am-u-sm-8">
                                                                <span><input type="text" id="keyname" value="" placeholder="商品关键字"></span>
                                                            </div>
                                                             <div class="am-u-sm-4">
                                                                 <button type="button" class="am-btn am-btn-primary" onclick="search();">搜索</button>
                                                             </div>
                                                        </div>
                                                </div>
                                            <div class="am-form-group">
                                                <div style=" width:400px; float:left; margin-left:380px;" >
                                                    <select  id="education" multiple="multiple"></select>
                                                </div>    
                                                <div style=" width:80px;float:left; text-align:center; margin-top:20px;" ><button type="button" onclick="moveAllSelectedToAnotherSelectObject('education','education1');">=></button><br><button type="button" onclick="moveAllSelectedToAnotherSelectObject('education1','education');"><=</button></div>
                                                <div style=" width:400px;float:left" >
                                                    <select  id="education1" multiple="multiple">
                                                          <?php foreach($goods as $k=>$v):?>
                                                          <option value="{$v}"> Id为：{$v}  <?php echo M('goods')->where(array('id'=>$v))->getField('name');?></option>
                                                          <?php endforeach;?>
                                                    </select>
                                                </div>

                                            </div>
                                            <div class="am-form-group ">
                                                                          <label for="user-email" class="am-u-sm-3 am-form-label">配送城市</label>
                                                                           <div class="am-u-sm-9">  
                                                                               <label class="am-checkbox-inline">
                                                                                    <input type="checkbox" id="AllCheck"  > 全选
                                                                                </label>
                                                                               <volist name="address" id="val">
                                                                                <label class="am-checkbox-inline">
                                                                                    <input type="checkbox" id="city_id" value="{$val.areaid}"<?php if(in_array($val['areaid'],$info['city_id'])):?> checked="checked"  <?php endif;?>name="city_id[]" > {$val.areaname}
                                                                                </label>
                                                                               </volist>    

                                                                             </div>  
                                                </div>
                                                  <div class="am-form-group ">
                                                                          <label for="user-email" class="am-u-sm-3 am-form-label">仓库列表</label>
                                                                           <div class="am-u-sm-9">  
                                                                               <label class="am-checkbox-inline">
                                                                                    <input type="checkbox" id="AllCheck1"  > 全选
                                                                                </label>
                                                                               <volist name="warehouse" id="val">
                                                                                <label class="am-checkbox-inline">
                                                                                    <input type="checkbox" id="warehouse_id" value="{$val.id}"<?php if(in_array($val['id'],$info['warehouse_id'])):?> checked="checked"  <?php endif;?>name="warehouse_id[]" > {$val.name}
                                                                                </label>
                                                                               </volist>    

                                                                             </div>  
                                                </div>
                                                <div class="am-form-group">
                                                        <label for="user-email" class="am-u-sm-3 am-form-label">首数量</label>
                                                        <div class="am-u-sm-3">
                                                            <input type="text"  datatype="/^[0-9]+$/" value="{$info.first_num}" nullmsg="不能为空" errormsg="格式错误" name="first_num" placeholder="首件数量">
                                                        </div>
                                                        <label for="user-email" class="am-u-sm-3 am-form-label">运费</label>
                                                        <div class="am-u-sm-3">
                                                            <input type="text"  datatype="/^[0-9]+(\.[0-9]{1,2})?$/" value="{$info.first_price}" nullmsg="不能为空" errormsg="格式错误" name="first_price" placeholder="首件费用">
                                                        </div>
                                                </div>
                                                <div class="am-form-group">
                                                        <label for="user-email" class="am-u-sm-3 am-form-label">递增数量</label>
                                                        <div class="am-u-sm-3">
                                                                <input type="text" datatype="/^[0-9]+$/" nullmsg="不能为空" errormsg="格式错误"  value="{$info.add_first_num}" name="add_first_num" placeholder="递增数量">
                                                        </div>
                                                        <label for="user-email" class="am-u-sm-3 am-form-label">递增费用</label>
                                                        <div class="am-u-sm-3">
                                                                <input type="text" datatype="/^[0-9]+(\.[0-9]{1,2})?$/" nullmsg="不能为空" errormsg="格式错误"  value="{$info.add_first_price}" name="add_first_price" placeholder="递增费用">
                                                        </div>
                                                </div>

                                                <div class="am-form-group">
                                                        <div class="am-u-sm-9 am-u-sm-push-3">
                                                                <input type="hidden" value="{$info.id}" name="id" />
                                                                <button type="submit" class="am-btn am-btn-primary"><notempty name="info">确认修改<else/>确认添加</notempty></button>
                                                        </div>
                                                </div>
                                        </form>
                                </div>
                        </div>
                </div>

		</div>

        </div>
<script type="text/javascript">  
  $('#AllCheck1').click(function(){
      var _self = this;
        $('input#warehouse_id').each(function(){
          this.checked = _self.checked;
      });
  });
    $('#AllCheck').click(function(){
      var _self = this;
        $('input#city_id').each(function(){
          this.checked = _self.checked;
      });
  });
 function search(){
     var keyname = $("#keyname").val();
   if(keyname == ''){
       alert('请输入关键字');
       return false;
   }
   var url = getUrl('Dispatching/search',{'keyname':keyname});
   $.get(url,function(data){
       if(data.errno == 1){
           var html = '';
           
          $.each(data.data,function(key,val){
              
              html+='<option value='+val.id+' >Id为：'+val.id+'  '+val.name+'</option>';
          })
          $('#education').html('');
          $('#education').append(html);
         
       }else{
           alert(data.msg);
       }
   },'json')
     
 }
  
function moveAllSelectedToAnotherSelectObject(fromObjSelectId, toObjectSelectId) {  
 var objSelect = document.getElementById(fromObjSelectId);
 var delNum = 0;
     if (null != objSelect && typeof(objSelect) != "undefined") {
        for(var i=0;i<objSelect.options.length;i=i+1) {  
            if(objSelect.options[i].selected) {  
                addOneItemToSelect(toObjectSelectId,objSelect.options[i].text,objSelect.options[i].value)
                objSelect.options.remove(i);
                i = i - 1;
            }
        }         
     } 
       var goods=',';
          $("#education1 option").each(function(){
             goods+=$(this).val()+',';
          })
          $("#goods").val(goods);
}
function addOneItemToSelect(objSelectId,objItemText,objItemValue) {  
 var objSelect = document.getElementById(objSelectId);
    if (null != objSelect && typeof(objSelect) != "undefined") {
        
      //判断是否该值的item已经在select中存在 
     if(isSelectItemExit(objSelectId,objItemValue)) {  
         if(objSelectId == 'education'){
             $("#education1 option[value='"+objItemValue+"'] ").remove();
         }
         $.messager.alert('提示消息','该值的选项已经存在!','info');
     }  else  {
         var varItem = new Option(objItemText,objItemValue);  
         objSelect.options.add(varItem);  
     }  
    } 
}

function isSelectItemExit(objSelectId,objItemValue)  {  
 var objSelect = document.getElementById(objSelectId);
    var isExit = false;  
    if (null != objSelect && typeof(objSelect) != "undefined") {
     for(var i=0;i<objSelect.options.length;i++) {  
         if(objSelect.options[i].value == objItemValue) {  
             isExit = true;  
             break;  
         }  
     }  
    }
    return isExit; 
 }
</script>  
	<script>
		call_submit_back_flag = true;
		function call_submit_back_func() {
			parent.zeroModal.closeAll();
		}
	</script>
</block>